import { defineStore } from "pinia";
import { ref } from 'vue'

export const useUserStore = defineStore('user', () => {
    const token = ref('')
    const setToken = (tokenVal: any) => {
        token.value = tokenVal
        setKey()
    }
    const clearToken = () => {
        token.value = ''
    }

    const key = ref(new Date() + '')
    const setKey = () => {
        key.value = new Date() + ''
    }
    class userInformationType {
        "createDate": string;
        "gender": number;
        "url": string;
        "id": string;
        "nickname": string;
        "username": string;
        "note": string;
        'isAnchor': number;
        "attention": any;
        "fans": any;
    }

    const userInformation = ref<userInformationType>({} as userInformationType);
    const setUserInformation = (val: userInformationType) => {
        userInformation.value = val
    }

    return {
        token, setToken, clearToken, userInformation, setUserInformation, key
    }
}, {
    persist: {
        storage: sessionStorage
    }
})